package view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;

import model.FileParser;
import model.Manuscript;
import model.State;
import model.User;

/**
 * @author Sarah George
 *
 */
@SuppressWarnings("serial")
public class AssignPaperToSPCAction extends AbstractAction {
	
	private State my_state;
	private Manuscript my_paper;
	
	public AssignPaperToSPCAction(Manuscript the_paper, State the_state) {
		super("Assign SPC");
	    putValue(Action.MNEMONIC_KEY, KeyEvent.VK_P);
	    putValue(Action.SELECTED_KEY, true);
	    my_state = the_state;
	    my_paper = the_paper;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		FileParser fp = my_state.getParser();
		int conf_id = my_state.getConference().getConfID();
		User[] spcs_in_conf = fp.getSPCsForConf(conf_id);
		JFrame spc_assign_frame = new JFrame("Assign a Subprogram Chair");
		AssignSPCPanel aspcp = new AssignSPCPanel(my_state, spc_assign_frame, spcs_in_conf, my_paper);
		/*
		 * set up jframe 
		 * combo box of spcs with check to not add if spc's user id == paper's author
		 * listener that saves spc chosen
		 * button that says cancel: dispose jframe  and 
		 * button that says ok: sets the spc chosen and disposes of jframe
		 */
		spc_assign_frame.add(aspcp,BorderLayout.CENTER);
		spc_assign_frame.setResizable(true); 
		spc_assign_frame.pack();
		spc_assign_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
		spc_assign_frame.setLocationRelativeTo(null);
		spc_assign_frame.setVisible(true);
	}

}
